﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using EntityDaoLibrary;
using System.Data;
using System.Collections;

namespace BusinessRules
{
    public class MIItemRelationZLRules
    {

        public MIItemRelationZLRules()
        {
        }


        #region 业务规则层操作
        public void insertEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                dao.insertEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public void updateEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                dao.updateEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public void deleteEntity(DataSet entityData)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            SingleTransaction tran = new SingleTransaction(data);
            tran.Begin();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                dao.deleteEntity(entityData);
                tran.Commit();
            }
            catch (Exception e)
            {
                tran.Rollback();
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public DataSet FindByPrimaryKey(object strKeyValue)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.FindByPrimaryKey(strKeyValue);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }


        public DataSet FindByPrimaryKey(ArrayList KeyValue)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.FindByPrimaryKey(KeyValue);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
        public DataSet FindAll()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.FindAll();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }

        /*重载FindAll方法，用来区分门诊和住院，clinicType 1 门诊，2住院
         * 
         * 修改人：郑宝力
         * 
         * 修改日期：2007年6月20日
         * 
         * */
        public DataSet FindAll(int clinicType)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.FindAll(clinicType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
        public string GetItemID(string itemid)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.GetItemID(itemid);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
        /*重载GetItemID方法，用来区分门诊和住院，clinicType 1 门诊，2住院
         * 
         * 修改人：郑宝力
         * 
         * 修改日期：2007年6月20日
         * 
         * */
        public string GetItemID(string itemid, int clinicType)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.GetItemID(itemid, clinicType);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }

        public void ImportNewData()
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                dao.ImportNewData();
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }

        }

        #endregion

        public DataSet DisplayCorrectInfo(DateTime dt)
        {
            IDataAccess data = DataAccessFactory.instance.CreateDataAccess();
            data.Open();
            try
            {
                MIItemRelationZLDAO dao = new MIItemRelationZLDAO(data);
                return dao.DisplayCorrectInfo(dt);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
            finally
            {
                data.Close();
            }
        }
    }
}
